/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <baja/model/generic_model.h>
#include <baja/types.hpp>
#include <baja/transition_tracking/transition_tracking_interfaces.h>

namespace baja { namespace transition_tracking {

namespace b = baja;
namespace bm = baja::model;
namespace bt = baja::transition_tracking;

class tracked_object :
    public bm::generic_model,
    public bt::itransition_target
{

    void tracked_object::registerInternal(
        const b::uint32& transitionType,
        const b::uint32& objectType,
        const b::uint32& objectId,
        const b::uint32& objectOrder);

    std::vector<bt::transition_path_node> _objectPath;
    std::shared_ptr<itransition_tracking_service> _trackingService;
    bool _undoRedoInProgress;

public:
    tracked_object();

    void setGenericParent(const std::shared_ptr<igeneric_model>& parent);

    void setTrackingService(
        const std::shared_ptr<itransition_tracking_service>& trackingService);

    void registerAttachChild(
        const b::uint32& transitionType,
        const b::uint32& childType,
        const b::uint32& childId,
        const b::uint32& childNumber);

    void registerCreateChild(
        const b::uint32& transitionType,
        const b::uint32& childType,
        const b::uint32& childId);

    void registerDetachChild(
        const b::uint32& transitionType,
        const b::uint32& childType,
        const b::uint32& childId,
        const b::uint32& childNumber);

    void registerDeleteChild(
        const b::uint32& transitionType,
        const b::uint32& childType,
        const b::uint32& childId);

    void registerCustomEvent(
        const b::uint32& transitionType);

    // itransition_target
    void buildTransitionPath(
        std::vector<bt::transition_path_node>& path
        );

    const std::vector<bt::transition_path_node>& transitionPath();

    void undo(
        const std::vector<bt::transition_path_node>& path,
        const b::uint32& index,
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

    void redo(
        const std::vector<bt::transition_path_node>& path,
        const b::uint32& index,
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

    // call backs into derived classes
    virtual void undoSelfAction(
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

    virtual void undoChildAction(
        const std::vector<bt::transition_path_node>& path,
        const b::uint32& childIndex,
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

    virtual void redoSelfAction(
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

    virtual void redoChildAction(
        const std::vector<bt::transition_path_node>& path,
        const b::uint32& childIndex,
        const std::shared_ptr<bt::itransition_parameters>& transitionParameters
        );

};

}} // baja::transition_tracking